/**
 *
 */
package jdk8日期;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.chrono.ChronoZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 *
 * @Title:
 * @author zhoujie
 * @date 2018年7月27日 上午9:39:35
 *
 */
public class LocalTimeUtil {

    /**
     *
     * @param time
     * @param pattern
     * @return
     */
    public static String formatTime(LocalDateTime time, String pattern) {
        return time.format(DateTimeFormatter.ofPattern(pattern));
    }

    /**
     *
     * @param time
     * @param pattern
     * @return
     */
    public static String formatTime(LocalTime time, String pattern) {
        return time.format(DateTimeFormatter.ofPattern(pattern));
    }

    /**
     *
     * @param time
     * @param pattern
     * @return
     */
    public static String formatTime(LocalDate time, String pattern) {
        return time.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static Date toDate(LocalDate time) {
        ZoneId zoneId = ZoneId.systemDefault();
        ChronoZonedDateTime<LocalDate> zonedDateTime = time.atStartOfDay(zoneId);
        return Date.from(zonedDateTime.toInstant());
    }

    public static LocalDate LoclDate(Date date) {
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        return instant.atZone(zoneId).toLocalDate();
    }
}